import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;


public class Servidor {

	private static String host = "localhost";
	private static int port = 5000;
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {

		
		try {
			ServerSocket srvSocket = new ServerSocket(port);
			Socket cliSocket = srvSocket.accept();
			
			DataInputStream dis = new DataInputStream(cliSocket.getInputStream());						
			DataOutputStream dos = new DataOutputStream(cliSocket.getOutputStream());
			Scanner sc = new Scanner(System.in);
			String line;
			
			do {			
				line = dis.readUTF();
				System.out.println(">> "+line);				
				
				System.out.print("Mensaje: ");
				line = sc.nextLine();
				dos.writeUTF(line);
			} while (!line.equals("END"));
			
			cliSocket.close();
			srvSocket.close();
			
			
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}

}
